<!DOCTYPE html>
<html lang="zh-cmn-Hans" prefix="og: http://ogp.me/ns#" class="han-init">
<head>
  <meta charset="utf-8">
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <link rel="icon" href="http://upeng.github.io/favicon.ico">
  <title>upeng</title>
  <link rel="stylesheet" href="/css/style.css">
  <link rel="stylesheet" href="/lib/fancybox/jquery.fancybox-1.3.4.css">
  <!--在这里倒入jquery 方便处理部分页面的jquery-->
  <script src="https://cdn.staticfile.org/jquery/1.7/jquery.min.js" type="text/javascript" ></script>
</head>
<body class="home">
	<header class="site-header navfixed-false">
  <div class="container">
      <h1><a href="/" title="upeng"><span class="octicon octicon-mark-github"></span> upeng</a></h1>
      <nav class="site-header-nav" role="navigation">
        
              
              <a href="/"  class=" site-header-nav-item hvr-underline-from-center" title="Home">Home</a>
        
              
              <a href="/categories/"  class=" site-header-nav-item hvr-underline-from-center" title="Categories">Categories</a>
        
              
              <a href="/bookmark/"  class=" site-header-nav-item hvr-underline-from-center" title="Bookmark">Bookmark</a>
        
              
              <a href="http://shareup.sinaapp.com"  class=" site-header-nav-item hvr-underline-from-center" title="Share">Share</a>
        
              
              <a href="/about/"  class=" site-header-nav-item hvr-underline-from-center" title="About">About</a>
        
      </nav>
  </div>
</header>

	<section class="banner-false">
    <div class="collection-head">
        <div class="container">
            <div class="collection-title">
                <h1 class="collection-header" id="site-description">
                    Learning Diary
                </h1>
                <div class="collection-info">
                    
                    
                        <span class="meta-info">
                            
                                <span class="octicon octicon-location">
                                   
                                        Beijing, China
                                    
                                </span>
                                
                            
                        </span>
                    
                        <span class="meta-info">
                            
                                <span class="octicon octicon-mark-github">
                                   
                                </span>
                                
                                    <a href="http://github.com/upeng" target="_blank">upeng</a>
                                
                            
                        </span>
                    
                        <span class="meta-info">
                            
                                <span class="octicon octicon-organization">
                                   
                                        weibo
                                    
                                </span>
                                
                            
                        </span>
                    
                </div>
            </div>
        </div>
    </div>
</section>
	   <section class="container">
    <div class="columns">
        <div class="column two-thirds">
            
                  <article id="post-php-detail" class="repo-list">
    <div class="repo-list-item" >
      <h3 class="repo-list-name" itemprop="name">
        
  
      <a class="article-title" href="/2016/05/28/php-detail/">几个值得深思的 PHP 面试问题</a>
  

      </h3>
      <div class="repo-list-description">
        
          <p>5个值得深思的 PHP 面试问题<br>文章所罗列的问题虽然看似简单，但是每个背后都涵盖了一个或几个大家容易忽视的基础知识点，希望能够帮助到你的面试和平时工作。<br>
        
      </div>
      <p class="repo-list-meta">
        <span class="meta-info">
          <span class="octicon octicon-calendar"></span>
           <time datetime="2016-05-27T16:04:26.000Z" itemprop="datePublished">2016-05-28</time>
        </span>

        
          <span class="meta-info">
            <span class="octicon octicon-file-directory"></span>
            <a href='/categories/PHP/' title=''>PHP</a>
          </span>
        
      
        <!--
          
        -->

      </p>
    </div>
  </article>
            
                  <article id="post-laravel-migration" class="repo-list">
    <div class="repo-list-item" >
      <h3 class="repo-list-name" itemprop="name">
        
  
      <a class="article-title" href="/2016/05/07/laravel-migration/">laravel migration</a>
  

      </h3>
      <div class="repo-list-description">
        
          <h2 id="laravel-migration工具"><a href="#laravel-migration工具" class="headerlink" title="laravel migration工具"></a>laravel migration工具</h2><h3 id="新建表articles步骤"><a href="#新建表articles步骤" class="headerlink" title="新建表articles步骤"></a>新建表<code>articles</code>步骤</h3><ul>
<li>migrations下生成<code>2015_12_13_104637_create_articles_table.php</code>文件<br><code>php artisan make:migration create_articles_table --create=articles</code></li>
<li>修改生成的文件<code>2015_12_13_104637_create_articles_table.php</code>
        
      </div>
      <p class="repo-list-meta">
        <span class="meta-info">
          <span class="octicon octicon-calendar"></span>
           <time datetime="2016-05-07T12:10:00.000Z" itemprop="datePublished">2016-05-07</time>
        </span>

        
          <span class="meta-info">
            <span class="octicon octicon-file-directory"></span>
            <a href='/categories/PHP/' title=''>PHP</a>
          </span>
        
      
        <!--
          
            <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/laravel/">laravel</a></li></ul>
          
        -->

      </p>
    </div>
  </article>
            
                  <article id="post-laravel-blade" class="repo-list">
    <div class="repo-list-item" >
      <h3 class="repo-list-name" itemprop="name">
        
  
      <a class="article-title" href="/2016/04/29/laravel-blade/">laravel的blade视图模板引擎</a>
  

      </h3>
      <div class="repo-list-description">
        
          <h3 id="blade模板引擎使用"><a href="#blade模板引擎使用" class="headerlink" title="blade模板引擎使用"></a>blade模板引擎使用</h3><p>很多时候，我们的view模板有很多重复的地方，比如head、footer部分，当然可以定义一些共用的部分，置于common文件夹下，然后使用include将其引入进来。而blade有一套自己的策略</p>
<p>比如定义一个<code>common.blade.php</code>文件，如下：</p>
<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Laravel&lt;/title&gt;
        &lt;link href=&quot;https://fonts.googleapis.com/css?family=Lato:100&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;
        &lt;style&gt;
            html, body {height: 100%;}
            body {margin: 0;width: 100%;display: table;font-weight: 100;font-family: &#39;Lato&#39;;}
            .container {text-align: center;display: table-cell;vertical-align: middle;
            }
            .content {text-align: center;display: inline-block;}
            .title {font-size: 96px;}
            .footer{color: green;font-size: 100px;}
        &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt; 
        &lt;div class=&quot;container&quot;&gt;
            @yield(&#39;content&#39;)
            @yield(&#39;footer&#39;)
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>
        
      </div>
      <p class="repo-list-meta">
        <span class="meta-info">
          <span class="octicon octicon-calendar"></span>
           <time datetime="2016-04-28T16:18:00.000Z" itemprop="datePublished">2016-04-29</time>
        </span>

        
          <span class="meta-info">
            <span class="octicon octicon-file-directory"></span>
            <a href='/categories/PHP/' title=''>PHP</a>
          </span>
        
      
        <!--
          
            <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/laravel/">laravel</a></li></ul>
          
        -->

      </p>
    </div>
  </article>
            
                  <article id="post-mysqlperformance03" class="repo-list">
    <div class="repo-list-item" >
      <h3 class="repo-list-name" itemprop="name">
        
  
      <a class="article-title" href="/2016/04/27/mysqlperformance03/">mysql数据库之索引优化</a>
  

      </h3>
      <div class="repo-list-description">
        
          <h2 id="如何选择合适的列建立索引"><a href="#如何选择合适的列建立索引" class="headerlink" title="如何选择合适的列建立索引?"></a>如何选择合适的列建立索引?</h2><ol>
<li>在where从句、group by从句、order by从句、on从句中出现的列</li>
<li>索引字段越小越好</li>
<li>离散度大的列放到联合索引的前面</li>
</ol>
<blockquote>
<p>理解离散度</p>
<pre><code>SELECT * FROM payment where staff_id = 2 AND customer_id = 584;
</code></pre><p>是index(staff_id, customer_id)好还是index(customer_id, staff_id)好？</p>
</blockquote>
<p><strong>备注</strong>：比较staff_id和customer_id两者的离散度，那个离散度高，那个列就放置到联合索引的前面<br>
        
      </div>
      <p class="repo-list-meta">
        <span class="meta-info">
          <span class="octicon octicon-calendar"></span>
           <time datetime="2016-04-26T16:44:33.000Z" itemprop="datePublished">2016-04-27</time>
        </span>

        
          <span class="meta-info">
            <span class="octicon octicon-file-directory"></span>
            <a href='/categories/MySQL/' title=''>MySQL</a>
          </span>
        
      
        <!--
          
            <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mysql/">mysql</a></li></ul>
          
        -->

      </p>
    </div>
  </article>
            
                  <article id="post-laravel-primary" class="repo-list">
    <div class="repo-list-item" >
      <h3 class="repo-list-name" itemprop="name">
        
  
      <a class="article-title" href="/2016/04/25/laravel-primary/">laravel初体验</a>
  

      </h3>
      <div class="repo-list-description">
        
          <h3 id="访问流程"><a href="#访问流程" class="headerlink" title="访问流程"></a>访问流程</h3><blockquote>
<p>路由文件routes.php</p>
</blockquote>
<pre><code>/*默认是以匿名函数的方式进行路由,/是当前域名下加载视图文件welcome.blade.php */

Route::get(&#39;/&#39;, function () {
    return view(&#39;welcome&#39;);
});
Route::get(&#39;/about&#39;, function () {
    return view(&#39;about&#39;);
});
Route::get(&#39;/blog&#39;, function () {
    return view(&#39;blog.content&#39;);  //其中的“.”可以用“/”代替
});

//如果使用非匿名函数的方式

Route::get(&#39;/&#39;, &#39;UserController@index&#39;);
Route::get(&#39;/about&#39;, &#39;UserController@about&#39;);
Route::get(&#39;/blog&#39;, &#39;UserController@blog&#39;);
</code></pre><h3 id="创建控制器"><a href="#创建控制器" class="headerlink" title="创建控制器"></a>创建控制器</h3><blockquote>
<ol>
<li>可以手动创建Controller，也可以使用命令行创建控制器<code>php artisan</code>工具</li>
<li>参数 –plain使用则不会生成一些默认的方法如index，create等</li>
</ol>
</blockquote>
<pre><code>php artisan make:controller UserController
php artisan make:controller TestController --plain
</code></pre><h3 id="视图的加载"><a href="#视图的加载" class="headerlink" title="视图的加载"></a>视图的加载</h3><blockquote>
<p>加载视图的方法</p>
</blockquote>
<pre><code>return view(&#39;welcome&#39;);
return view(&#39;blog/title&#39;);
return view(&#39;blog.content&#39;);
</code></pre><blockquote>
<p>怎么向blade视图传递变量</p>
</blockquote>
<pre><code>$name = &#39;&lt;p style=&quot;color:red&quot;&gt;upfriend&lt;/p&gt;&#39;;
$time = date(&#39;Y-m-d&#39;, time());
$arr = array(&#39;first&#39; =&gt; &#39;jerry&#39;, &#39;last&#39; =&gt; &#39;bool&#39;);

//传递变量-通用方式传递给$data数组
$data[&#39;name&#39;] = $name;
$data[&#39;time&#39;] = $time; 
return view(&#39;blog.content&#39;, $data);

//Laravel链式操作方式 
return view(&#39;blog.content&#39;)-&gt;(&#39;name&#39; =&gt; $name);  //传递一个变量
return view(&#39;blog.content&#39;)-&gt;with(array(&#39;name&#39; =&gt; $name, &#39;time&#39; =&gt; $time));  //传递数组变量

//compact方法
return view(&#39;blog.content&#39;, compact(&#39;name&#39;, &#39;time&#39;, &#39;arr&#39;));  //去掉$的变量名
</code></pre><blockquote>
<p>如何正确输出变量的值</p>
</blockquote>
<pre><code>//原生PHP输出数据方式，默认会对变量中的字符会进行转义（xss?）
&lt;h1&gt;&lt;?=name?&gt;&lt;/h1&gt;   

//Laravel的blade模板引擎渲染方式，两个大括号{{}}表示转义后输出
&lt;h1&gt;{{name}}&lt;/h1&gt;  //浏览器输出&lt;p style=&quot;color:red&quot;&gt;upfriend&lt;/p&gt;

&lt;h1&gt;{!!name!!}&lt;/h1&gt;  //会见变量作为html,输出红色字体的upfriend
</code></pre>
        
      </div>
      <p class="repo-list-meta">
        <span class="meta-info">
          <span class="octicon octicon-calendar"></span>
           <time datetime="2016-04-25T12:10:00.000Z" itemprop="datePublished">2016-04-25</time>
        </span>

        
          <span class="meta-info">
            <span class="octicon octicon-file-directory"></span>
            <a href='/categories/PHP/' title=''>PHP</a>
          </span>
        
      
        <!--
          
            <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/laravel/">laravel</a></li></ul>
          
        -->

      </p>
    </div>
  </article>
            
        </div>
        <div class="column one-third">
          <h3>Search</h3>


<div id="site_search">
	<form action="http://www.google.com/search?" data-site="http://upeng.github.io">
    	<input type="text" id="search_box" name="q" placeholder="Search" style="width: 253px;">
    	<button type="button" class="btn btn-default" id="site_search_do"><span class="octicon octicon-search"></span></button>
    </form>
</div>

<ul id="search_results"></ul>
<h3>Repositories</h3>

    
    <div class="popular-container"></div>
    
    <script type="text/template" id="popular-list-template">
        <a href="{%=clone_url%}" class="card text-center" target="_blank">
            <div class="thumbnail">
                <div class="card-image geopattern" data-pattern-id="{%=name%}">
                    <div class="card-image-cell">
                        <h3 class="card-title">
                            {%=name%}
                        </h3>
                    </div>
                </div>
                <div class="caption">
                    <div class="card-description">
                        <p class="card-text">
                            {%=description%}
                        </p>
                    </div>
                    <div class="card-text">
                        <span class="meta-info tooltipped tooltipped-n" aria-label="{%=stargazers_count%} stars">
                            <span class="octicon octicon-star"></span> {%=stargazers_count%}
                        </span>
                        <span class="meta-info tooltipped tooltipped-n" aria-label="{%=forks_count%} forks">
                            <span class="octicon octicon-git-branch"></span> {%=forks_count%}
                        </span>
                        <span class="meta-info tooltipped tooltipped-n" aria-label="最后更新时间：{%=updated_at%}">
                            <span class="octicon octicon-clock"></span>
                            <time datetime="{%=updated_at%}">{%=updated_at%}</time>
                        </span>
                    </div>
                </div>
            </div>
        </a>
    </script>

    <script src="/js/baiduTemplate.js"></script>
    <script type="text/javascript">
        var popular_repos = function(){

            var baiduTpl = new Object();

            var handleTpl = function(){
                baiduTpl.popular_list = baidu.template("popular-list-template");
            };

            var handleGithub = function(){
                var popularContainer = $(".popular-container");

                var repos = "upeng.github.io,codeIgniter-captcha,learn-vuejs".split(",");
                for(var i in repos){
                    var name = repos[i];
                    $.get("https://api.github.com/repos/upeng/"+name,handle);
                }

                function handle(result){
                    result.updated_at = result.updated_at.split("T")[0];
                    if(result){
                        var html = baiduTpl.popular_list(result);
                        popularContainer.append(html);
                        $(".geopattern").each(function(){           
                            $(this).geopattern($(this).data('pattern-id'));
                        });
                    }
                }
            };

            return {
                init:function(){
                    handleTpl();
                    handleGithub();
                }
            }
        }; 
        $(popular_repos().init);
    </script>

        </div>
    </div>

    
      <div class="pagination text-align">
          <div class="btn-group">
              <a class="extend prev" rel="prev" href="/archives/2016/page/4/">&laquo;</a><a class="page-number" href="/archives/2016/">1</a><span class="space">&hellip;</span><a class="page-number" href="/archives/2016/page/3/">3</a><a class="page-number" href="/archives/2016/page/4/">4</a><span class="page-number current">5</span><a class="page-number" href="/archives/2016/page/6/">6</a><a class="page-number" href="/archives/2016/page/7/">7</a><a class="extend next" rel="next" href="/archives/2016/page/6/">&raquo;</a>
          </div>
      </div>
    
</section>

<footer class="container">
    <div class="site-footer" role="contentinfo">
        <div class="copyright left mobile-block">
                © 2016
                <span title="yupeng">yupeng</span>
                <a href="javascript:window.scrollTo(0,0)" class="right mobile-visible">TOP</a>
        </div>

        <ul class="site-footer-links right mobile-hidden">
            <li>
                <a href="javascript:window.scrollTo(0,0)" >TOP</a>
            </li>
        </ul>

        <a href="https://github.com/upeng" target="_blank" aria-label="view source code">
            <span class="mega-octicon octicon-mark-github" title="GitHub"></span>
        </a>

        <ul class="site-footer-links mobile-hidden">
            
                  
                  <li>
                    <a href="/"  title="Home">Home</a>
                  </li>
            
                  
                  <li>
                    <a href="/categories/"  title="Categories">Categories</a>
                  </li>
            
                  
                  <li>
                    <a href="/bookmark/"  title="Bookmark">Bookmark</a>
                  </li>
            
                  
                  <li>
                    <a href="http://shareup.sinaapp.com"  title="Share">Share</a>
                  </li>
            
                  
                  <li>
                    <a href="/about/"  title="About">About</a>
                  </li>
            
            <li>
                <a href="/atom.xml">
                    <span class="octicon octicon-rss" style="color:orange;"></span>
                </a>
            </li>
        </ul>
    </div>
</footer>


		<script src="/js/geopattern.js"></script>

		

		<script src="/js/highlight.pack.js"></script>
		<script src="/lib/fancybox/jquery.fancybox-1.3.4.pack.js"></script>

		<script src="/js/index.js"></script>

		 <script src="/js/popular_repo.js"></script> 

	</body>
</html>